package com.ruoyi.project.plan.welding.controller;

import java.util.List;

import com.ruoyi.project.device.space.domain.BasCargoSpace;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.plan.welding.domain.PlanWelding;
import com.ruoyi.project.plan.welding.service.IPlanWeldingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊接计划表Controller
 * 
 * @author wld
 * @date 2023-04-20
 */
@Controller
@RequestMapping("/plan/welding")
public class PlanWeldingController extends BaseController
{
    private String prefix = "plan/welding";

    @Autowired
    private IPlanWeldingService planWeldingService;

    @GetMapping()
    public String welding()
    {
        return prefix + "/welding";
    }

    /**
     * 查询焊接计划表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlanWelding planWelding)
    {
//        startPage();
        List<PlanWelding> list = planWeldingService.selectPlanWeldingList(planWelding);
        return getDataTable(list);
    }

    /**
     * 导出焊接计划表列表
     */
    @Log(title = "焊接计划表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlanWelding planWelding)
    {
        List<PlanWelding> list = planWeldingService.selectPlanWeldingList(planWelding);
        ExcelUtil<PlanWelding> util = new ExcelUtil<PlanWelding>(PlanWelding.class);
        return util.exportExcel(list, "焊接计划表数据");
    }

    /**
     * 新增焊接计划表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊接计划表
     */
    @Log(title = "焊接计划表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlanWelding planWelding)
    {
        return toAjax(planWeldingService.insertPlanWelding(planWelding));
    }

    /**
     * 修改焊接计划表
     */
    @GetMapping("/edit/{sbId}")
    public String edit(@PathVariable("sbId") Long sbId, ModelMap mmap)
    {
        PlanWelding planWelding = planWeldingService.selectPlanWeldingBySbId(sbId);
        mmap.put("planWelding", planWelding);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊接计划表
     */
    @Log(title = "焊接计划表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlanWelding planWelding)
    {
        return toAjax(planWeldingService.updatePlanWelding(planWelding));
    }

    /**
     * 删除焊接计划表
     */
    @Log(title = "焊接计划表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(planWeldingService.deletePlanWeldingBySbIds(ids));
    }

    /**
     * 选择物品
     */
    @GetMapping("/selectPro")
    public String selectPro(){
        return prefix + "/selectPro";
    }
    /**
     * 设备库房是否锁定修改
     */
    @Log(title = "设备库房管理", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeLocked(PlanWelding planWelding)
    {
        return toAjax(planWeldingService.updatePlanWelding(planWelding));
    }

}
